import request from "@/utils/request";
import type { AddCartDTO, CartItemVO } from "@/types/cartType";


enum ENUM {
   addCartAPI = "/member/cart",
   fetchCartListAPI = "/member/cart",
   deleteCartAPI = "/member/cart",
   updateCartGoodAPI = "/member/cart",
   changeCheckedAllAPI = "/member/cart/selected"
}

/**
 * @description 加入购物车的接口
 * */
export const addCartAPI = (data: AddCartDTO) => request<CartItemVO>({
   url: ENUM.addCartAPI,
   method: "POST",
   data,
});

/**
 * @description 获取购物车列表的接口
 * */
export const fetchCartListAPI = () => request<CartItemVO[]>({
   url: ENUM.fetchCartListAPI,
   method: "GET",
});

/**
 * @description 删除购物车商品的接口
 * */
export const deleteCartAPI = (skuIds: string[]) => request<void>({
   url: ENUM.deleteCartAPI,
   method: "DELETE",
   data: {
      ids: skuIds,
   },
});

/**
 * @description 修改购物车商品的接口
 * */
export const updateCartGoodAPI = (skuId: string, data: { selected?: boolean, count?: number }) => request<CartItemVO[]>({
   url: `${ENUM.updateCartGoodAPI}/${skuId}`,
   method: "PUT",
   data,
});

/**
 *@description 全选/取消全选的接口
 * */
export const changeCheckedAllAPI = (selected: boolean) => request({
   url: ENUM.changeCheckedAllAPI,
   method: "PUT",
   data: {
      selected,
   },
});